package Weibo;

import java.util.Iterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Checking {

	public int brithday(String str) {
		int w = 0;
		String pat = "\\d{4}-\\d{2}-\\d{2}";
		Pattern p = Pattern.compile(pat);
		Matcher m = p.matcher(str);
		if (m.matches()) {
			w = 1;
		} else {
			w = 0;
		}
		return w;
	}

	public int phone(Set<User> user, String str) {
		int w = 0;
		Iterator<User> iter = user.iterator();
		String pat = "^(13|15|17|18)\\d{9}$";
		Pattern p = Pattern.compile(pat);
		Matcher m = p.matcher(str);
		if (m.matches()) {
			while (iter.hasNext()) {
				if (str.equals(iter.next().getPhone())) {
					w = 1;
			}
		}
		}
		return w;
	}

	public int email(Set<User> user,String str) {
		int w = 0;
		Iterator<User> iter = user.iterator();
		String pat = "\\w+@\\w+.(com|cn|net|gov|edu|org|com.cn)";
		Pattern p = Pattern.compile(pat);
		Matcher m = p.matcher(str);
		if (m.matches()) {
			while (iter.hasNext()) {
				if (str.equals(iter.next().getEmail())) {
					w = 1;
			}
		} 
		}
		return w;
	}

	public int chachong(Set<User> user, String str1) {
		Iterator<User> iter = user.iterator();
		while (iter.hasNext()) {
			if (str1.equals(iter.next().getName())) {
				return 1;
			}
		}
		return 0;
	}
}
